<?php
/* Project Parasynthesis
*  Author: Fujiwara Sai
*  Usage: Json Show
*/

require_once './parasy/SimpleCommon.inc.php';

/*if ( USE_ZEND == "TRUE"){
	/* 3rdparty Zend Framework cores 
	ini_set('include_path', 'D:/Discuz!EXP/libs/zf/1.0.0-RC1/'. ini_get('include_path'));
	require_once('Zend/Json.php');
}*/

if (isset($_GET['m'])) {
	$m = strtolower(trim($_GET['m']));
} else {
	$m = 'home';
}

switch ($m) {
	default:
	case 'home':
		dheader("Location: {$boardurl}");
		break;

	case 'json_home_tab_latest':
		require_once DISCUZ_ROOT.'./forumdata/cache/cache_toplist.php';
		$top = array();
		$i = 0;
		foreach($_DCACHE['newthread'] as $topic) {
			if ((!in_array($topic['fid'], $disabled_forums))) {
				$i++;
				$top[$i]['tid'] = $topic['tid'];
				$top[$i]['uid'] = $topic['uid'];
				$top[$i]['subject'] = iconv('gbk', 'utf-8', $topic['subject']);
				$top[$i]['author'] = iconv('gbk', 'utf-8', $topic['author']);
				$top[$i]['author_en'] = rawurlencode($topic['author']);
				$top[$i]['avatar'] = avRESIZE($topic['avatar'],'s');
				$top[$i]['name'] = iconv('gbk', 'utf-8', $topic['name']);
				$top[$i]['board_name'] = $topic['board_name'];
				$top[$i]['lastpost'] = iconv('gbk', 'utf-8', make_descriptive_time($topic['lastpost']));
				$top[$i]['replies'] = $topic['replies'];
				$top[$i]['color'] = rand_color();
			}
		}
		session_start();
		$_SESSION['home_tab'] = 'latest';
		header('Content-type: text/plain; charset=utf-8');
		header('Cache-control: no-cache, must-revalidate');
		if (function_exists('json_encode')) {
			$encoded = json_encode($top);
		} else {
			$encoded = Zend_Json::encode($top);
		}
		echo $encoded;
		break;
		
	case 'json_now_latest':
		require_once DISCUZ_ROOT.'./forumdata/cache/cache_nowhere.php';
		$now = array();
		$i = 0;
		foreach($_DCACHE['nowhere'] as $nowhere) {
			$i++;
			if ($i < 21){
				$now[$i]['vid'] = $nowhere['vid'];
				$now[$i]['author'] = iconv('gbk', 'utf-8', $nowhere['author']);
				$now[$i]['authorid'] = $nowhere['authorid'];
				$now[$i]['author_en'] = rawurlencode($nowhere['author']);
				$now[$i]['avatar'] = avRESIZE($nowhere['avatar'],'s');
				$now[$i]['content'] = iconv('gbk', 'utf-8', $nowhere['content']);
				$now[$i]['dateline'] = iconv('gbk', 'utf-8', make_descriptive_time($nowhere['dateline']));
				$now[$i]['color'] = rand_color();
			}
		}
		session_start();
		$_SESSION['home_tab'] = 'now';
		header('Content-type: text/plain; charset=utf-8');
		header('Cache-control: no-cache, must-revalidate');
		if (function_exists('json_encode')) {
			$encoded = json_encode($now);
		} else {
			$encoded = Zend_Json::encode($now);
		}
		echo $encoded;
		break;
		
	case 'json_timeline':
		$timeline =  timeline_remix();
		header('Content-type: text/plain; charset=gbk');
		include template('dashboard_timeline');
		break;
}



?>